<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>随心交友</title>
    <!-- Bootstrap -->
    <link rel="stylesheet" href="../static/ajax/lib/bootstrap/css/bootstrap.min.css"
          th:href="@{/ajax/lib/bootstrap/css/bootstrap.min.css}">
    <link rel="stylesheet" href="../static/css/login.css" th:href="@{/css/login.css}">
</head>


<body>
<div class="container">
    <div class="row">
        <div class="col-md-offset-3 col-md-6">
            <form class="form-horizontal" th:onsubmit="return false" th:id="loginForm">
                <span class="heading">用户登录</span>
                <div class="form-group">
                    <input type="email" class="form-control" th:id="loginName" th:name="loginName"
                           placeholder="用户名或电子邮件">
                    <i class="fa fa-user"></i>
                </div>
                <div class="form-group help">
                    <input type="password" class="form-control" th:id="password" placeholder="密　码" th:name="password">
                    <i class="fa fa-lock"></i>
                    <a href="#" class="fa fa-question-circle"></a>
                </div>
                <div class="form-group">
                    <div class="main-checkbox">
                        <input type="checkbox" value="None" id="checkbox1" name="check"/>
                        <label for="checkbox1"></label>
                    </div>
                    <span class="text">Remember me</span>
                    <input type="submit" class="btn btn-default" th:value="登陆" onclick="login()">
                </div>
            </form>
        </div>
    </div>
</div>
<script src="../static/js/jquery-3.4.1.js" th:src="@{/js/jquery-3.4.1.js}"></script>
<script src="../static/ajax/lib/bootstrap/js/bootstrap.min.js"
        th:src="@{/ajax/lib/bootstrap/js/bootstrap.min.js}"></script>
</body>
</html>
<script th:inline="javascript">
    function login() {
        $.ajax({
            type: "POST",
            dataType: "json",
            url: "/login",
            data: $('#loginForm').serialize(),
            success: function (data) {
                console.log(data);
                if (data.status == 200) {
                    var id = data.data;
                    console.log(id)
                    window.location.href = "/chat/getChat?id="+id;
                } else {
                    alert(data.msg);
                }
            },
            error: function () {
                alert("操作异常!");
            }
        });
    }
</script>